package servlet.admin.characters;

import entity.Characters;
import entity.Modular;
import service.CharacterService;
import service.PermissionService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet( name = "AdminCharactersServlet")
public class AdminCharactersServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        CharacterService service=new CharacterService();
        List<Characters> list=service.adminCharacters();
        String cp=request.getParameter("cp");
        request.setAttribute("list",list);
        switch (cp) {
            case "characters":
                request.getServletContext().getRequestDispatcher("/admin/characters.jsp").forward(request, response);
                break;
            case "permission":
                request.getServletContext().getRequestDispatcher("/admin/permission.jsp").forward(request, response);
                break;
            case "modular":
                PermissionService permissionService = new PermissionService();
                List<Modular> list1 = permissionService.modularList();//所有的权力

                request.setAttribute("list1", list1);
                request.getServletContext().getRequestDispatcher("/admin/modular.jsp").forward(request, response);
                break;
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
